<html>
<head><meta charset="utf-8"><title>Is metadata updated in place? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html">Is metadata updated in place?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="230728026"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230728026" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230728026">(Mar 17 2021 at 16:59)</a>:</h4>
<p>Say I have a tool that wants to add a new metadata field that's serialized across crates. Is it possible to update the .rmeta/.rlib file in place? or do I have to figure out what logic <code>--emit=metadata</code> uses and replicate that?</p>



<a name="230729751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230729751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230729751">(Mar 17 2021 at 17:09)</a>:</h4>
<p>looks like existing logic is in <a href="https://github.com/rust-lang/rust/blob/04ae50179a802d1d18bb780baa85f55864f56616/compiler/rustc_interface/src/passes.rs#L979-L1002">https://github.com/rust-lang/rust/blob/04ae50179a802d1d18bb780baa85f55864f56616/compiler/rustc_interface/src/passes.rs#L979-L1002</a></p>



<a name="230730205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230730205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230730205">(Mar 17 2021 at 17:11)</a>:</h4>
<p>ok, actually emitting metadata happens in <a href="https://github.com/rust-lang/rust/blob/04ae50179a802d1d18bb780baa85f55864f56616/compiler/rustc_metadata/src/rmeta/encoder.rs#L2071">https://github.com/rust-lang/rust/blob/04ae50179a802d1d18bb780baa85f55864f56616/compiler/rustc_metadata/src/rmeta/encoder.rs#L2071</a>, and it looks like it's not customizable at all</p>



<a name="230730251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230730251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230730251">(Mar 17 2021 at 17:12)</a>:</h4>
<p>that is unfortunate</p>



<a name="230730262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230730262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230730262">(Mar 17 2021 at 17:12)</a>:</h4>
<p>The rmeta files are written by rustc_metadata::rmeta::encode_metadata_impl. This is a serialisation of the metadata information with leb128 encoding.</p>



<a name="230730295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230730295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230730295">(Mar 17 2021 at 17:12)</a>:</h4>
<p>At most you could use custom attributes.</p>



<a name="230730351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230730351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230730351">(Mar 17 2021 at 17:12)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20metadata.20updated.20in.20place.3F/near/230730295">said</a>:</p>
<blockquote>
<p>At most you could use custom attributes.</p>
</blockquote>
<p>there's non trivial work being done though, the tool needs access to MIR among other things</p>



<a name="230730410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230730410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230730410">(Mar 17 2021 at 17:13)</a>:</h4>
<p>so just "this function is important" isn't enough to store all the needed data</p>



<a name="230730456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230730456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230730456">(Mar 17 2021 at 17:13)</a>:</h4>
<p>the concrete use case is <a href="https://github.com/willcrichton/example-analyzer">https://github.com/willcrichton/example-analyzer</a></p>



<a name="230730601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230730601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230730601">(Mar 17 2021 at 17:14)</a>:</h4>
<p>What does it do?</p>



<a name="230730728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230730728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230730728">(Mar 17 2021 at 17:15)</a>:</h4>
<p>it stores a map of where functions are called (not defined)</p>



<a name="230730750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230730750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230730750">(Mar 17 2021 at 17:15)</a>:</h4>
<p><a href="https://github.com/willcrichton/example-analyzer/blob/265259af66fbd5b400f30ce7ea848a4ee7dffdac/src/main.rs#L42">https://github.com/willcrichton/example-analyzer/blob/265259af66fbd5b400f30ce7ea848a4ee7dffdac/src/main.rs#L42</a></p>



<a name="230730874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230730874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230730874">(Mar 17 2021 at 17:15)</a>:</h4>
<p>and then uses that to highlight the documentation <a href="https://cdn.discordapp.com/attachments/786784478731305000/788098168067457024/Screen_Shot_2020-12-14_at_12.40.17_PM.png">https://cdn.discordapp.com/attachments/786784478731305000/788098168067457024/Screen_Shot_2020-12-14_at_12.40.17_PM.png</a></p>
<div class="message_inline_image"><a href="https://cdn.discordapp.com/attachments/786784478731305000/788098168067457024/Screen_Shot_2020-12-14_at_12.40.17_PM.png"><img src="https://cdn.discordapp.com/attachments/786784478731305000/788098168067457024/Screen_Shot_2020-12-14_at_12.40.17_PM.png"></a></div>



<a name="230731009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230731009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230731009">(Mar 17 2021 at 17:16)</a>:</h4>
<p>Could it use <code>-Zalways-encode-mir</code> and then find all calls while documenting?</p>



<a name="230731037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230731037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230731037">(Mar 17 2021 at 17:16)</a>:</h4>
<p>oh huh that's a much better idea</p>



<a name="230731153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230731153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230731153">(Mar 17 2021 at 17:18)</a>:</h4>
<p>it doesn't work for examples, only dependencies, but that's what I wanted metadata for in the first place</p>



<a name="230731229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230731229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230731229">(Mar 17 2021 at 17:18)</a>:</h4>
<p><span class="user-mention" data-user-id="265377">@Will Crichton</span> I'll see if I have time this weekend to write up a demo</p>



<a name="230731297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230731297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230731297">(Mar 17 2021 at 17:19)</a>:</h4>
<p>wait no that breaks - the uses are in <em>downstream</em> crates</p>



<a name="230731356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230731356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230731356">(Mar 17 2021 at 17:19)</a>:</h4>
<p>when documenting <code>hyper</code>, <code>warp</code> hasn't yet been documented</p>



<a name="230731418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230731418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230731418">(Mar 17 2021 at 17:19)</a>:</h4>
<p>and there's no dependency from warp -&gt; hyper, only from hyper -&gt; warp</p>



<a name="230731439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230731439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230731439">(Mar 17 2021 at 17:19)</a>:</h4>
<p>hmm</p>



<a name="230731593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230731593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230731593">(Mar 17 2021 at 17:20)</a>:</h4>
<p>Oh, can it be stored in a separate metadata file?</p>



<a name="230731651"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230731651" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230731651">(Mar 17 2021 at 17:20)</a>:</h4>
<p>yeah I think that would be necessary</p>



<a name="230732165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230732165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230732165">(Mar 17 2021 at 17:24)</a>:</h4>
<p>I think an alternate solution is to document crates in reverse order</p>



<a name="230732277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230732277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230732277">(Mar 17 2021 at 17:24)</a>:</h4>
<p>say you have <code>log -&gt; hyper -&gt; warp</code> - you document warp <em>first</em>, finding uses of the hyper API, store them in the out-of-band output file, then document <code>hyper</code>, then document <code>log</code> in the same way</p>



<a name="230732335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230732335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230732335">(Mar 17 2021 at 17:25)</a>:</h4>
<p>which works because <em>documenting</em> crates is independent (up until now), it's only the metadata from rustc that's a hard dependency</p>



<a name="230732694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20metadata%20updated%20in%20place%3F/near/230732694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Will Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20metadata.20updated.20in.20place.3F.html#230732694">(Mar 17 2021 at 17:27)</a>:</h4>
<p>Fwiw, I think the tool would be useful even if it only finds examples in the current crate (either crate source or examples directory). Finding examples in downstream crates is nice but not essential for an MVP.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>